<?
function Str2Hex($st) {
	if ($st != "") {
		$res = "";
		for ($i=0; $i<strlen($st); $i++) {
			if ($i>0) $res .= ",";
	                $res .= bin2hex($st[$i]); 
		}
		return $res;
	} else {
		return "";
	}
}

function Hex2Str($Hex) {
	$tok = strtok ($Hex,",");
	$st = "";
	while ($tok) {
		$i = 0;
		switch ($tok[0]){
	                case "A":
	                case "B":
	                case "C":
	                case "D":
	                case "E":
	                case "F":
	                	$i += ord($tok[0])-ord("A")+10;                	
	                break;
	                default:
	                	$i += ord($tok[0])-ord("0");                	
                	break;
	        }
	        $i *=16;
		switch ($tok[1]){
	                case "A":
	                case "B":
	                case "C":
	                case "D":
	                case "E":
	                case "F":
	                	$i += ord($tok[1])-ord("A")+10;                	
	                break;
	                default:
	                	$i += ord($tok[1])-ord("0");                	
                	break;
	        }
	    $st .= chr($i); 
	    $tok = strtok (",");
	}
	return $st; 
}
?> 
